package com.sportradar.assessment.work.core;


import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sportradar.assessment.work.beans.ConfigurationBean;
import com.sportradar.assessment.work.services.ExecutionManager;
import com.sportradar.assessment.work.services.MultiplicationFiveProgression;
import com.sportradar.assessment.work.services.NumberProgression;
import com.sportradar.assessment.work.threads.ExecutionThread;
import com.sportradar.assessment.work.threads.StatisticsReporterThread;
import com.sportradar.assessment.work.util.ConfigUtil;
import com.sportradar.assessment.work.util.Constants;

/*
 * Main class for the project: (for command line launch)
 * Create Services and run two threds for number progression and configuration refresh
 * and schedule one additional thread for statistics with fixed interval of repetition 
 * 
 */
public class SportradarAssessment {

	private static Logger logger=LoggerFactory.getLogger(SportradarAssessment.class);
	private static final long REPORT_INTERVAL_IN_SECONDS=60L;
		
	public static void main(String[] args) {

			
		ConfigurationBean firstSettings=ConfigUtil.update();
		NumberProgression numberProgression=new MultiplicationFiveProgression();
		ExecutionManager threadManager= new ExecutionManager(numberProgression,firstSettings);
				 
		String thread1Name=ConfigUtil.getPropertyValue(Constants.THREAD_1_NAME_KEY);
		String thread2Name=ConfigUtil.getPropertyValue(Constants.THREAD_2_NAME_KEY);
			
		Runnable thread1=new ExecutionThread(thread1Name,threadManager);
		Runnable thread2=new ExecutionThread(thread2Name,threadManager);
		Runnable statisticsThread=new StatisticsReporterThread(threadManager);
	
		ScheduledThreadPoolExecutor executor= new ScheduledThreadPoolExecutor(3);
		executor.scheduleWithFixedDelay(statisticsThread,REPORT_INTERVAL_IN_SECONDS,REPORT_INTERVAL_IN_SECONDS, TimeUnit.SECONDS);
		executor.execute(thread1);
		executor.execute(thread2);

		

	}
	


	

}
